package com.hbvtc.xxxy.nikeSale.frames;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.hbvtc.xxxy.nikeSale.models.Salesman;
import com.hbvtc.xxxy.nikeSale.services.Nikeservices;

public class MainFramesNike extends JFrame {
	// 构造方法
	public MainFramesNike() {
		// 设置尺寸大小
		this.setSize(730, 600);
		// 设置标题
		this.setTitle("nike销售管理系统");
		// 设置移动窗体的大小
		this.setResizable(true);
		// 设置窗体居中
		this.setLocationRelativeTo(null);

		// 设置标题栏的图标
		ImageIcon imageIcon = new ImageIcon(getClass().getResource("01.png"));
		this.setIconImage(imageIcon.getImage());

		// 背景图片的路径
		String path = "images/001.jpg";
		ImageIcon background = new ImageIcon(path);
		// 把背景图片显示在一个标签里面
		JLabel label = new JLabel(background);
		// 把标签的大小位置设置为图片刚好填充整个面板
		label.setBounds(0, 0, this.getWidth(), this.getHeight());
		// 把内容窗格转化为JPanel，否则不能用方法setOpaque()来使内容窗格透明
		JPanel imagePanel = (JPanel) this.getContentPane();
		imagePanel.setOpaque(false);
		// 把背景图片添加到分层窗格的最底层作为背景
		this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// ========登录的组件===============
		JLabel lalAccount = new JLabel("账    号:");
		lalAccount.setFont(new Font(null, 0, 20));
		JLabel lalPwd = new JLabel("密    码:");
		lalPwd.setFont(new Font(null, 0, 20));

		final JTextField txtAccount = new JTextField();
		txtAccount.setFont(new Font(null, 0, 20));
		final JTextField txtPwd = new JPasswordField();
		txtPwd.setFont(new Font(null, 0, 20));

		JButton btnRegister = new JButton("立即登录");
		btnRegister.setFont(new Font(null, 0, 20));
		btnRegister.setContentAreaFilled(false);
		JButton btnLog = new JButton("立即注册");
		btnLog.setFont(new Font(null, 0, 20));
		btnLog.setContentAreaFilled(false);
		JButton btnQuit = new JButton("退出系统");
		btnQuit.setFont(new Font(null, 0, 20));
		btnQuit.setContentAreaFilled(false);

		// =======组件添加到的布局里面
		this.add(btnRegister);
		this.add(btnLog);
		this.add(btnQuit);
		this.add(txtAccount);
		this.add(txtPwd);
		this.add(lalAccount);
		this.add(lalPwd);
		// ========登录的布局==============
		this.setLayout(null);
		btnRegister.setBounds(280, 360, 150, 40);
		btnRegister.setFont(new Font(null,0,24));
		btnLog.setBounds(120, 450, 180, 40);
		btnLog.setFont(new Font(null,0,24));
		btnQuit.setBounds(400, 450, 180, 40);
		btnQuit.setFont(new Font(null,0,24));

		lalAccount.setBounds(180, 100, 100, 40);
		lalAccount.setFont(new Font(null,0,24));
		lalPwd.setBounds(180, 180, 100, 40);
		lalPwd.setFont(new Font(null,0,24));

		txtAccount.setBounds(300, 100, 220, 35);
		txtAccount.setFont(new Font(null,0,24));
		txtPwd.setBounds(300, 180, 220, 35);
		txtPwd.setFont(new Font(null,0,24));
		
		//这个是点击登录页面
		btnRegister.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				//跳转登录进去的页面
				Integer id=Integer.parseInt(txtAccount.getText().trim());
				String pwd=txtPwd.getText().trim();
				Nikeservices nikeservices=new Nikeservices();
				Salesman salesman = null;
				try {
					//获取id和name
					salesman = nikeservices.inSalesman(id, pwd);	
					
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				//对输入的密码进行判断
				if( salesman.getPwd()!=null){
					new SuccessSalesmanNike();
					dispose();//关闭本页面
				}else{
					JOptionPane.showMessageDialog(MainFramesNike.this, "登录失败");
				}
			}
		});
		//这个是点击注册的界面
		btnLog.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				//跳转到信息注册的界面
				new GoodsShopNike();
			}
		});
		//这个是点击退出系统的界面
		btnQuit.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.exit(0);
			}
		});
	}

	public static void main(String[] args) {
		MainFramesNike framesNike=new MainFramesNike();
		framesNike.setVisible(true);
	}
	
}
